package init

import (
	"api-gateway/basic/config"
	"api-gateway/untils"
	"log"

	__ "api-gateway/basic/proto"
	"google.golang.org/grpc"
	"google.golang.org/grpc/credentials/insecure"
)

func GrpcInit() {

	client, err := untils.NewConsulClient("14.103.138.112:8500")
	if err != nil {
		panic(err)
		return
	}

	cfg := untils.GRPCServer{
		Name:    "house-src",
		Tags:    []string{"house-src"},
		Port:    50051,
		Address: "127.0.0.1",
	}

	err = client.RegisterServer(&cfg)
	if err != nil {
		panic(err)
		return
	}

	// Set up a connection to the server.
	conn, err := grpc.NewClient("127.0.0.1:50051", grpc.WithTransportCredentials(insecure.NewCredentials()))
	if err != nil {
		log.Fatalf("did not connect: %v", err)
	}
	config.HouseClient = __.NewHouseClient(conn)

}
